package com.pernix.authen.net;

import java.io.*;
/*
 * This class defines the different type of messages that will be exchanged between the
 * Clients and the Server. 
 * When talking from a Java Client to a Java Server a lot easier to pass Java objects, no 
 * need to count bytes or to wait for a line feed at the end of the frame
 */
public class ChatMessage implements Serializable {

	protected static final long serialVersionUID = 1112122200L;

	// The different types of message sent by the Client
	// WHOISIN to receive the list of the users connected
	// MESSAGE an ordinary message
	// LOGOUT to disconnect from the Server
	static final int WHOISIN = 0, MESSAGE = 1, LOGOUT = 2, REQ_SERVER_CHALLENGE = 3, RES_SERVER_CHALLENGE = 4, REQ_AUTHEN_RESPONSE = 5, RES_AUTHEN_RESPONSE = 6;
	private int type;
	private String message;
	private String userName;
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	private byte[] authenMessage;
	private byte[] peerChallenge;
	public void setPeerChallenge(byte[] peerChallenge) {
		this.peerChallenge = peerChallenge;
	}

	public byte[] getPeerChallenge() {
		return peerChallenge;
	}

	public byte[] getAuthenMessage() {
		return authenMessage;
	}

	// constructor
	ChatMessage(int type, String message) {
		this.type = type;
		this.message = message;
	}
	ChatMessage(int type, byte[] authMessage){
		this(type, authMessage, null, null);
	}
	
	ChatMessage(int type, byte[] authMessage, byte[] peerChallenge, String username){
		this.type = type;
		this.userName = username;
		this.peerChallenge = peerChallenge;
		this.authenMessage = authMessage;
	}
	
	// getters
	int getType() {
		return type;
	}
	String getMessage() {
		return message;
	}
}
